package com.chapter.sample.juc;

import java.util.concurrent.TimeUnit;

/**
 * 守护线程、用户线程
 */
public class DeamonDemo {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + " Come in " + (Thread.currentThread().isDaemon() ? "守护线程" : "用户线程"));
        }, "a");
        thread.setDaemon(true);
        thread.start();

        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {

        }
        System.out.println(Thread.currentThread().getName() + " Come in " + (Thread.currentThread().isDaemon() ? "守护线程" : "用户线程"));
    }
}
